package com.qingke.business;

import org.apache.ibatis.session.SqlSession;

import com.qingke.Command.UserCommand;
import com.qingke.mapper.RecordeMapper;
import com.qingke.memo.MemoConsole;
import com.qingke.memo.MemoDao;

public class DeleteCommand extends UserCommand{

	@Override
	public void executeUserCommand() {
		SqlSession session = MemoDao.mybatisSession();
		RecordeMapper recordeM = session.getMapper(RecordeMapper.class);
		System.out.println("请输入你要删除的id(可先list了解一下id)");
		int id;
		while(true){
			id = Integer.parseInt(MemoConsole.askUserInput("cmd >"));
			if(recordeM.selectOne(id)==null){
				System.out.println("输入的id不正确，请重新输入！");
			}else {
				break;
			}
		}
		recordeM.deleteByPrimaryKey(id);
		session.commit();
		System.out.println("删除成功！");
	}

}
